home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / haziran / 19 / setup.exe / data.z / pbclib.h < prev    next >
C/C++ Source or Header  |  2001-04-11  |  12KB  |  321 lines

  1. ////////////////////////////////////////////////////////////////
  2. // File - V3pbclib.h
  3. //
  4. // Library for 'WinDriver for V3 Semiconductor PBC family of devices. 
  5. // The basic idea is to get a handle for the board
  6. // with V3PBC_Open() and use it in the rest of the program
  7. // when calling WD functions.  Call V3PBC_Close() when done.
  8. // 
  9. ////////////////////////////////////////////////////////////////
  10.  
  11. #ifndef _PBCLIB_H_
  12. #define _PBCLIB_H_
  13.  
  14. #include "../../samples/shared/pci_regs.h"
  15. #include "../../samples/shared/bits.h"
  16.  
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20.  
  21. enum { V3PBCLIB_VER = 100 };
  22.     
  23. // PCI Configuration registers definitions 
  24. enum {
  25.     V3PBC_PCI_VENDOR      = 0x00,
  26.     V3PBC_PCI_DEVICE      = 0x02,
  27.     V3PBC_PCI_CMD         = 0x04,
  28.     V3PBC_PCI_STAT        = 0x06,
  29.     V3PBC_PCI_CC_REV      = 0x08,
  30.     V3PBC_PCI_HDR_CFG     = 0x0c,
  31.     V3PBC_PCI_IO_BASE     = 0x10,
  32.     V3PBC_PCI_BASE0       = 0x14,
  33.     V3PBC_PCI_BASE1       = 0x18,
  34.     V3PBC_PCI_SUB_VENDOR  = 0x2c,
  35.     V3PBC_PCI_SUB_ID      = 0x2e,
  36.     V3PBC_PCI_ROM         = 0x30,
  37.     V3PBC_PCI_BPARM       = 0x3c,
  38.     V3PBC_PCI_MAP0        = 0x40,
  39.     V3PBC_PCI_MAP1        = 0x44,
  40.     V3PBC_INT_STAT        = 0x48,
  41.     V3PBC_INT_CFG         = 0x4c,
  42.     V3PBC_LB_BASE0        = 0x54,
  43.     V3PBC_LB_BASE1        = 0x58,
  44.     V3PBC_LB_MAP0         = 0x5e,
  45.     V3PBC_LB_MAP1         = 0x62,
  46.     V3PBC_LB_IO_BASE      = 0x6e,
  47.     V3PBC_FIFO_CFG        = 0x70,
  48.     V3PBC_FIFO_PRIORITY   = 0x72,
  49.     V3PBC_FIFO_STAT       = 0x74,
  50.     V3PBC_LB_ISTAT        = 0x76,
  51.     V3PBC_LB_IMASK        = 0x77,
  52.     V3PBC_SYSTEM          = 0x78,
  53.     V3PBC_LB_CFG          = 0x7a,
  54.     V3PBC_DMA_PCI_ADDR0   = 0x80,
  55.     V3PBC_DMA_LOCAL_ADDR0 = 0x84,
  56.     V3PBC_DMA_LENGTH0     = 0x88,  // mask off upper 8 bits 
  57.     V3PBC_DMA_CSR0        = 0x8b,
  58.     V3PBC_DMA_CTLB_ADR0   = 0x8c,
  59.     V3PBC_DMA_PCI_ADDR1   = 0x90,
  60.     V3PBC_DMA_LOCAL_ADDR1 = 0x94,
  61.     V3PBC_DMA_LENGTH1     = 0x98,  // mask off upper 8 bits 
  62.     V3PBC_DMA_CSR1        = 0x9b,
  63.     V3PBC_DMA_CTLB_ADR1   = 0x9c,
  64.     V3PBC_IFL_TAIL        = 0xa0, // implemented on revision B2
  65.     V3PBC_IFL_HEAD        = 0xa4, // implemented on revision B2
  66.     V3PBC_IPL_TAIL        = 0xa8, // implemented on revision B2
  67.     V3PBC_IPL_HEAD        = 0xac, // implemented on revision B2
  68.     V3PBC_OPL_TAIL        = 0xb0, // implemented on revision B2
  69.     V3PBC_OPL_HEAD        = 0xb4, // implemented on revision B2
  70.     V3PBC_OFL_TAIL        = 0xb8, // implemented on revision B2
  71.     V3PBC_OFL_HEAD        = 0xbc, // implemented on revision B2
  72.     V3PBC_MAIL_DATA0      = 0xc0,
  73.     V3PBC_MAIL_DATA1      = 0xc1,
  74.     V3PBC_MAIL_DATA2      = 0xc2,
  75.     V3PBC_MAIL_DATA3      = 0xc3,
  76.     V3PBC_MAIL_DATA4      = 0xc4,
  77.     V3PBC_MAIL_DATA5      = 0xc5,
  78.     V3PBC_MAIL_DATA6      = 0xc6,
  79.     V3PBC_MAIL_DATA7      = 0xc7,
  80.     V3PBC_MAIL_DATA8      = 0xc8,
  81.     V3PBC_MAIL_DATA9      = 0xc9,
  82.     V3PBC_MAIL_DATA10     = 0xca,
  83.     V3PBC_MAIL_DATA11     = 0xcb,
  84.     V3PBC_MAIL_DATA12     = 0xcc,
  85.     V3PBC_MAIL_DATA13     = 0xcd,
  86.     V3PBC_MAIL_DATA14     = 0xce,
  87.     V3PBC_MAIL_DATA15     = 0xcf,
  88.     V3PBC_MAIL_IEWR       = 0xd0,
  89.     V3PBC_MAIL_IERD       = 0xd2,
  90.     V3PBC_LB_MAIL_IEWR    = 0xd4,
  91.     V3PBC_LB_MAIL_IERD    = 0xd6,
  92.     V3PBC_MAIL_WR_STAT    = 0xd8,
  93.     V3PBC_MAIL_RD_STAT    = 0xda,
  94.     V3PBC_QBA_MAP         = 0xdc // implemented on revision B2
  95. };
  96.  
  97. typedef enum {
  98.     V3PBC_REV_A  = 0,
  99.     V3PBC_REV_B0 = 1,
  100.     V3PBC_REV_B1 = 2,
  101.     V3PBC_REV_B3 = 3,
  102. } V3PBC_REV;
  103.  
  104. typedef enum
  105. {
  106.     V3PBC_ADDR_IO_BASE = AD_PCI_BAR0,
  107.     V3PBC_ADDR_BASE0   = AD_PCI_BAR1,
  108.     V3PBC_ADDR_BASE1   = AD_PCI_BAR2,
  109.     V3PBC_ADDR_ROM     = AD_PCI_BAR_EPROM
  110. } V3PBC_ADDR;
  111.  
  112. typedef enum
  113. {
  114.     V3PBC_MODE_BYTE   = 0,
  115.     V3PBC_MODE_WORD   = 1,
  116.     V3PBC_MODE_DWORD  = 2
  117. } V3PBC_MODE;
  118.  
  119. enum { V3PBC_RANGE_REG = 0x00000100 };
  120.  
  121. typedef struct V3PBC_STRUCT *V3PBCHANDLE;
  122.  
  123. typedef struct
  124. {
  125.     DWORD dwCounter;   // number of interrupts received
  126.     DWORD dwLost;      // number of interrupts not yet dealt with
  127.     BOOL fStopped;     // was interrupt disabled during wait
  128.     DWORD dwStatusReg; // value of status register when interrupt occured
  129. } V3PBC_INT_RESULT;
  130. typedef void (WINAPI *V3PBC_INT_HANDLER)( V3PBCHANDLE hV3, V3PBC_INT_RESULT *intResult);
  131.  
  132. typedef struct
  133. {
  134.     WD_INTERRUPT Int;
  135.     HANDLE hThread;
  136.     WD_TRANSFER Trans[2];
  137.     V3PBC_INT_HANDLER funcIntHandler;
  138. } V3PBC_INTERRUPT;
  139.  
  140. typedef struct
  141. {
  142.     DWORD dwLocalBase;
  143.     DWORD dwMask;
  144.     DWORD dwBytes;
  145.     DWORD dwAddr;
  146.     DWORD dwAddrDirect;
  147.     BOOL  fIsMemory;
  148. } V3PBC_ADDR_DESC;
  149.  
  150. typedef struct V3PBC_STRUCT
  151. {
  152.     HANDLE hWD;
  153.     WD_CARD cardLock;
  154.     WD_PCI_SLOT pciSlot;
  155.     WD_CARD_REGISTER cardReg;
  156.     V3PBC_ADDR_DESC addrDesc[AD_PCI_BARS];
  157.     BOOL   fUseInt;
  158.     V3PBC_INTERRUPT Int;
  159.     DWORD  dwReg_PCI_MAP0;
  160. } V3PBC_STRUCT;
  161.  
  162. typedef enum
  163. {
  164.     V3_DMA_0 = 0,
  165.     V3_DMA_1 = 1
  166. } V3_DMA_CHANNEL;
  167.  
  168. // options for V3PBC_Open
  169. enum { V3PBC_OPEN_USE_INT =   0x1 };
  170.  
  171. // Count number of cards in PCI bus with given VendorID / DeviceID 
  172. // dwVendorID / dwDeviceID -    the VendorID / DeviceID of cards to count
  173. // dwVendorId - PCI Vendor ID to detect. If 0, detects cards from all vendors.
  174. // dwDeviceId - PCI Device ID to detect. If 0, detects all devices.
  175. // if both are '0', counts all PCI cards
  176. DWORD V3PBC_CountCards (DWORD dwVendorID, DWORD dwDeviceID);
  177.  
  178. // Opens a handle to a V3PBC card.  The handle will be used in future calls to the card
  179. // nCardNum - differentiates between cards with same VendorID / DeviceID on the bus (0,1,...)
  180. // dwOptions - 0 if no interrupts needed, or V3PBC_OPEN_USE_INT for use of interrupts in session
  181. // You may use the wildcard option in dwDeviceID / dwVendorID (i.e. use '0') to open all
  182. // cards detected in V3PBC_CountCards (use a loop...)
  183. BOOL V3PBC_Open (V3PBCHANDLE *phV3, DWORD dwVendorID, DWORD dwDeviceID, DWORD nCardNum, DWORD dwOptions);
  184.  
  185. // must be called when ending session.  Frees handle to card.
  186. void V3PBC_Close (V3PBCHANDLE hV3);
  187.  
  188. // returns TRUE if addrSpace exists
  189. BOOL V3PBC_IsAddrSpaceActive(V3PBCHANDLE hV3, V3PBC_ADDR addrSpace);
  190.  
  191. // returns the V3 PBC silicon revision (equates defined in V3PBC_REV)
  192. DWORD V3PBC_GetRevision(V3PBCHANDLE hV3);
  193.  
  194. // Read a block of data from card to buffer
  195. // buf - buffer to read data into
  196. // addrSpace - Address space on card to read from 
  197. // dwLocalAddr - offset of address to read, in the address space
  198. // dwBytes - number of bytes to read
  199.  
  200. // Write a block of data from buffer to card 
  201. // buf - buffer to write data from
  202. // addrSpace - Address space on card to write to
  203. // dwLocalAddr - offset of address to write to, in the address space
  204. // dwBytes - number of bytes to write
  205.  
  206. // The following functions Read/Write a Byte/Word/DWord to/from an address space on the card
  207. // addrSpace - Address space on card to read to / write from 
  208. // dwOffset - offset of address to read to / write from, in the address space
  209. // data - the data to write.
  210. BYTE V3PBC_ReadSpaceByte (V3PBCHANDLE hV3, V3PBC_ADDR addrSpace, DWORD dwOffset);
  211. void V3PBC_WriteSpaceByte (V3PBCHANDLE hV3, V3PBC_ADDR addrSpace, DWORD dwOffset, BYTE data);
  212. WORD V3PBC_ReadSpaceWord (V3PBCHANDLE hV3, V3PBC_ADDR addrSpace, DWORD dwOffset);
  213. void V3PBC_WriteSpaceWord (V3PBCHANDLE hV3, V3PBC_ADDR addrSpace, DWORD dwOffset, WORD data);
  214. DWORD V3PBC_ReadSpaceDWord (V3PBCHANDLE hV3, V3PBC_ADDR addrSpace, DWORD dwOffset);
  215. void V3PBC_WriteSpaceDWord (V3PBCHANDLE hV3, V3PBC_ADDR addrSpace, DWORD dwOffset, DWORD data);
  216. // Block transfers
  217. void V3PBC_ReadSpaceBlock (V3PBCHANDLE hV3, DWORD dwOffset, PVOID buf, 
  218.                     DWORD dwBytes, V3PBC_ADDR addrSpace);
  219. void V3PBC_WriteSpaceBlock (V3PBCHANDLE hV3, DWORD dwOffset, PVOID buf, 
  220.                      DWORD dwBytes, V3PBC_ADDR addrSpace);
  221.  
  222. // The following functions Read/Write a Byte/Word/DWord to/from a local address on the card
  223. // dwLocalAddr - local address to read to / write from
  224. // data - the data to write.
  225. BYTE V3PBC_ReadByte (V3PBCHANDLE hV3, DWORD dwLocalAddr);
  226. void V3PBC_WriteByte (V3PBCHANDLE hV3, DWORD dwLocalAddr, BYTE data);
  227. WORD V3PBC_ReadWord (V3PBCHANDLE hV3, DWORD dwLocalAddr);
  228. void V3PBC_WriteWord (V3PBCHANDLE hV3, DWORD dwLocalAddr, WORD data);
  229. DWORD V3PBC_ReadDWord (V3PBCHANDLE hV3, DWORD dwLocalAddr);
  230. void V3PBC_WriteDWord (V3PBCHANDLE hV3, DWORD dwLocalAddr, DWORD data);
  231. // Block transfers
  232. void V3PBC_ReadBlock (V3PBCHANDLE hV3, DWORD dwLocalAddr, PVOID buf, DWORD dwBytes);
  233. void V3PBC_WriteBlock (V3PBCHANDLE hV3, DWORD dwLocalAddr, PVOID buf, DWORD dwBytes);
  234.  
  235. // The following functions Read/Write a Byte/Word/DWord to/from a register
  236. // data - the data to write.
  237. void V3PBC_WriteRegByte (V3PBCHANDLE hV3, DWORD dwReg, BYTE bData);
  238. BYTE V3PBC_ReadRegByte (V3PBCHANDLE hV3, DWORD dwReg);
  239. void V3PBC_WriteRegWord (V3PBCHANDLE hV3, DWORD dwReg, WORD wData);
  240. WORD V3PBC_ReadRegWord (V3PBCHANDLE hV3, DWORD dwReg);
  241. void V3PBC_WriteRegDWord (V3PBCHANDLE hV3, DWORD dwReg, DWORD dwData);
  242. DWORD V3PBC_ReadRegDWord (V3PBCHANDLE hV3, DWORD dwReg);
  243.  
  244. // Enable / Disable interrupt handler routines
  245. BOOL V3PBC_IntIsEnabled (V3PBCHANDLE hV3);
  246. BOOL V3PBC_IntEnable (V3PBCHANDLE hV3, V3PBC_INT_HANDLER funcIntHandler);
  247. void V3PBC_IntDisable (V3PBCHANDLE hV3);
  248.  
  249. // access PCI configuration registers
  250. DWORD V3PBC_ReadPCIReg(V3PBCHANDLE hV3, DWORD dwReg);
  251. void V3PBC_WritePCIReg(V3PBCHANDLE hV3, DWORD dwReg, DWORD dwData);
  252.  
  253. // Initializes the WD_DMA structure (see windrvr.h) and allocates a contiguous buffer
  254. BOOL V3PBC_DMAOpen(V3PBCHANDLE hV3, WD_DMA *pDMA, DWORD dwBytes);
  255.  
  256. // Frees the DMA handle, and frees the allocated contiguous buffer
  257. void V3PBC_DMAClose(V3PBCHANDLE hV3, WD_DMA *pDMA);
  258.  
  259. // Start DMA to/from card.
  260. // pDMA - initialized with V3PBC_DMAOpen
  261. // fRead - TRUE: read from card to buffer.  FALSE: write from buffer to card
  262. // fBlocking - TRUE: wait until DMA is done
  263. // dwBytes - number of bytes to transfer (must be a multiple of 4)
  264. // dwOffset - offset in DMA buffer to read to / write from.
  265. // dwLocalAddr - local address on card to write to / read from
  266. BOOL V3PBC_DMAStart(V3PBCHANDLE hV3, V3_DMA_CHANNEL dmaChannel, WD_DMA *pDMA, BOOL fRead,
  267.     BOOL fBlocking, DWORD dwBytes, DWORD dwOffset, DWORD dwLocalAddr);
  268.  
  269. // Used to test if DMA is done. (Use when V3PBC_DMAStart was called with fBlocking==FALSE) 
  270. BOOL V3PBC_DMAIsDone(V3PBCHANDLE hV3, V3_DMA_CHANNEL dmaChannel);
  271.  
  272. // Sends a reset signal to the card, for a period of 'wDelay' milliseconds
  273. void V3PBC_PulseLocalReset(V3PBCHANDLE hV3, WORD wDelay);
  274.  
  275. // initialize I2C bus
  276. void V3PBC_EEPROMInit(V3PBCHANDLE hV3);
  277.  
  278. // Programs one byte to the EEPROM
  279. // bAddr - address to write to 
  280. // bData - data to write
  281. BOOL V3PBC_EEPROMWrite(V3PBCHANDLE hV3, BYTE bSlaveAddr, BYTE bAddr, BYTE bData);
  282.  
  283. // Reads one byte to the EEPROM
  284. // bAddr - address to read from  
  285. // bData - data read.
  286. BOOL V3PBC_EEPROMRead(V3PBCHANDLE hV3, BYTE bSlaveAddr, BYTE bAddr, BYTE *bData);
  287.  
  288. // this string is set to an error message, if one occurs
  289. extern CHAR V3PBC_ErrorString[];
  290.  
  291. // System register bit equates 
  292. enum {
  293.     SYSTEM_RST_OUT   = BIT15,
  294.     SYSTEM_LOCK      = BIT14,
  295.     SYSTEM_SPROM_EN  = BIT13,
  296.     SYSTEM_SCL       = BIT12,
  297.     SYSTEM_SDA_OUT   = BIT11,
  298.     SYSTEM_SDA_IN    = BIT10
  299. };
  300.  
  301. enum { SYSTEM_UNLOCK_TOKEN   = 0xa05f };
  302.  
  303. // I2C Bus states
  304. enum {
  305.     I2C_WRITE = 0,
  306.     I2C_READ = 1
  307. };
  308.  
  309. // number of times a master will try and write to a slave device 
  310. enum { I2C_RETRY = 10 };
  311. enum { I2C_1010  = 0x50 };
  312.  
  313. enum { SYSTEM_SDA_IN_SHIFT   = 10 };
  314.  
  315.  
  316. #ifdef __cplusplus
  317. }
  318. #endif
  319.  
  320. #endif
  321.